<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./lib/font/iconfont.css" />
    <style>
      * {
        box-sizing: border-box;
      }

      .maoyan {
        width: 375px;
        height: 667px;
        border: 1px solid #000;
        position: relative;
      }

      header {
        width: 100%;
        height: 156px;
        background-color: lightblue;
      }

      .rated {
        width: 100%;
        height: 205px;
        background-color: bisque;
        padding: 12px 15px;
      }

      .title {
        font-size: 14px;
        color: #333;
        margin: 0 0 12px;
      }

      .ul {
        width: 100%;
        height: 148px;
        display: flex;
        overflow: auto;
      }

      .item {
        width: 85px;
        height: 143px;
        margin-right: 10px;
        background-color: aqua;
        flex-shrink: 0;

        /* 
          给父元素加的6个
            display: flex;
            flex-direction   主轴方向
            justify-content
            align-items
            flex-wrap
            align-content
          给子元素加的6个
            flex-glow
            flex-shrink
            flex-basis
            flex
            order
            align-self
        */
      }

      img {
        width: 85px;
        height: 110px;
      }

      .footer {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 50px;
        background-color: aquamarine;
        display: flex;
      }
      .footer-item {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
      }

      .active {
        color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <mao-yan></mao-yan>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const MaoYanHeader = {
        template: `
          <header></header>
        `,
      };

      const MaoYanItem = {
        props: ["item"],
        template: `
          <div class="item">
            <img :src="item.imgUrl" />
            <div>{{ item.title }}</div>
          </div>
        `,
      };

      const MaoYanRated = {
        data() {
          return {
            list: [], // 12项的数组
          };
        },
        template: `
          <div class="rated">
            <p class="title">最受好评电影</p>
            <div class="ul">
              <mao-yan-item v-for="item in list" :key="item._id" :item="item"></mao-yan-item>
            </div>
          </div>
        `,
        components: {
          MaoYanItem,
        },
        mounted() {
          fetch("http://www.pudge.wang:3080/api/rated/list")
            .then((response) => response.json())
            .then((res) => {
              console.log(res.result);
              this.list = res.result;
            });
        },
      };

      const MaoYanFooter = {
        data() {
          return {
            list: [
              {
                icon: "dianying",
                title: "首页",
              },
              {
                icon: "xiaoshipinyingshi48",
                title: "视频",
              },
              {
                icon: "yanchu",
                title: "演出",
              },
              {
                icon: "xiaoshipinyingshi48",
                title: "视频",
              },
              {
                icon: "xiaoshipinyingshi48",
                title: "视频",
              },
            ],
            ativeNum: 0,
          };
        },
        template: `
          <div class="footer">
            <div
              class="footer-item"
              v-for="(item, index) in list"
              :key="index"
              :class="{active: index === ativeNum}"
              @click="ativeNum = index"
            >
              <span class="iconfont" :class="'icon-' + item.icon"></span>
              <span>{{ item.title }}</span>
            </div>
          </div>
        `,
      };

      const MaoYan = {
        template: `
          <div class="maoyan">
            <mao-yan-header></mao-yan-header>
            <mao-yan-rated></mao-yan-rated>
            <mao-yan-footer></mao-yan-footer>
          </div>
        `,
        components: {
          MaoYanHeader,
          MaoYanRated,
          MaoYanFooter,
        },
      };

      createApp({
        data() {
          return {};
        },
        components: {
          MaoYan,
        },
      }).mount("#app");
    </script>
  </body>
</html>
